﻿using System;
using System.ComponentModel.DataAnnotations;
using XCI.Extensions;
using XCI.Helper;

namespace XCI.Annotations
{
    /// <summary>
    /// 传真号码验证属性
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public class FaxAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value.IsEmpty()) return ValidationResult.Success;
            var result = ValidateHelper.IsTelPhone(value.ToStringOrEmpty());
            return result ? ValidationResult.Success : new ValidationResult(ErrorMessage ?? "请输入正确的传真号码");
        }
    }
}
